<?php
	function send_mail($name,$from,$to,$subject,$message)
	{        
		$mess =$message;
		$headers = "From: ".$name." <".$from.">\n";
		$headers .= "Reply-To: ".$name." <".$from.">\n";
		$headers .= "MIME-Version: 1.0\n";
		$headers .= "Content-Type: text/html; charset=\"utf-8\"\n";
		return @mail( $to, $subject, $mess, $headers );          
	}
	
	function send($to,$subject,$message)
	{
		$CI = get_instance(); 
		$mess =$message;
		$contact_name = "=?UTF-8?B?".base64_encode($CI->config->item('contact_name')).'?=';
		$headers = "From: ".$contact_name." <".$CI->config->item('contact_email').">\n";
		$headers .= "Reply-To: ".$contact_name." <".$CI->config->item('contact_email').">\n";
		$headers .= "MIME-Version: 1.0\n";
		$headers .= "Content-Type: text/html; charset=UTF-8\n";
		return @mail( $to, "=?UTF-8?B?".base64_encode($subject).'?=', $mess, $headers );          
	}
	
	function sendshare($nguoigui,$emailnguoigui,$emailnguoinhan,$subject,$message)
	{
		$CI = get_instance();          
		$mess =$message;
		$nguoigui = "=?UTF-8?B?".base64_encode($nguoigui).'?='; 
		$headers = "From: ".$nguoigui." <".$emailnguoigui.">\n";
		$headers .= "Reply-To: ".$nguoigui." <".$emailnguoigui.">\n";
		$headers .= "MIME-Version: 1.0\n";
		$headers .= "Content-Type: text/html; charset=UTF-8\n";
		return @mail( $emailnguoinhan, "=?UTF-8?B?".base64_encode($subject).'?=', $mess, $headers );          
	} 
	
	function info_send_mail()
	{
		$CI = get_instance();
		$CI->load->config('config_contact');
		$mess = '<div>----------------------------</div>';
		$mess .='<div><b>'.$CI->config->item('contact_name').'</b></div>';
		$mess .='<div><b>Địa chỉ:</b> '.$CI->config->item('contact_address').'</div>';
		$mess .='<div><b>Điện thoại:</b> '.$CI->config->item('contact_phone').' - '.$CI->config->item('contact_mobile').'</div>';
		$mess .='<div><b>Email:</b> '.$CI->config->item('contact_email').'</div>';
		$mess .='<div><b>Fax:</b> '.$CI->config->item('contact_fax').'</div>';
		return $mess;
	}  
	
	function sendmail($mailto, $nameto, $subject, $content, $frommail='', $fromname='')
	{
		date_default_timezone_set(date_default_timezone_get());
		
		require_once APPPATH."libraries/class.smtp.php"; 
		require_once APPPATH."libraries/class.phpmailer.php";
		
		//Thông tin xac thực
		$mail             = new PHPMailer();
		//$mail->Mailer 	  = "smtp";
		/*$mail->Host       = "mail.quagiare.com";
		$mail->SMTPAuth   = true;
		$mail->Username   = "info@quagiare.com";
		$mail->Password   = "yRGXL3qB";
		$mail->IsHTML(true) ;
		$mail->From       = "info@quagiare.com";	//$frommail ; 
		$mail->FromName   = "www.quagiare.com"; //$fromname ;*/
		
		$mail->IsSMTP();
		$mail->SMTPAuth   = true;
		$mail->SMTPSecure = "ssl";
		$mail->Host       = "smtp.gmail.com";
		$mail->Port       = 465;
		$mail->SMTPAuth   = true;
		$mail->Username   = "wwworgsvn@gmail.com"; //"quagiare02@gmail.com";
		$mail->Password   = "w4016216";	//"quagiare1986";
		$mail->AddReplyTo("quagiare@gmail.com", "www.quagiare.com");
		$mail->SetFrom("quagiare@gmail.com", "www.quagiare.com");
		$mail->IsHTML(true) ;
		//send to email
		$mail->AddAddress($mailto, $nameto);
		$mail->Subject    = $subject ;
		$mail->MsgHTML($content);
		return $mail->Send() ;
	}
?>
